﻿@using Microsoft.Web.Mvc
@using SapaFinance.DTO
@using SapaFinance.UI.Controllers
@model RequestDTO
<fieldset>
    <legend>Заявка</legend>
    @Html.HiddenFor(c => c.UID)
    @{
        if (@Model.UID != Guid.Empty)
        {
        <div class="display-label">@Html.LabelFor(m => @Model.Number): @Html.DisplayFor(m => @Model.Number)</div>
            Html.RenderPartial("EditorTemplates/ChangableDTO", @Model);
        }
    }
    <table>
        <tr>
            <td>
                <div class="display-label">@Html.LabelFor(m => @Model.SelectedPayee)</div>
                @{ Html.RenderAction<CorporationController>(x => x.RenderPayee(@Model.SelectedPayee.HasValue ? @Model.SelectedPayee.Value : Guid.Empty)); }
                <div class="display-label">@Html.LabelFor(m => @Model.SelectedPayer)</div>
                <div id="updatePayer">
                    @{ Html.RenderAction<CorporationController>(x => x.RenderPayer(@Model.SelectedPayer)); }
                </div>
                <div class="display-label">@Html.LabelFor(m => @Model.SelectedBudgetItem)</div>
                @{ Html.RenderAction<BudgetItemController>(x => x.RenderBudgetItem(@Model.SelectedBudgetItem)); }
                <div class="display-label">@Html.LabelFor(m => @Model.SelectedPaymentType)</div>
                @{ Html.RenderAction<PaymentTypeController>(x => x.RenderPaymentType(@Model.SelectedPaymentType)); }
                <div class="display-label">@Html.LabelFor(m => @Model.PaymentPeriod)</div>
                <div class="editor-field">@Html.EditorFor(m => @Model.PaymentPeriod)</div>
                <div class="display-label">@Html.LabelFor(m => @Model.Payment) @Html.ValidationMessageFor(x => x.Payment)</div>
                <div class="editor-field">@Html.EditorFor(m => @Model.Payment)</div>
                <div class="display-label">@Html.LabelFor(m => @Model.TaxRate)</div>
                <div class="editor-field">@Html.EditorFor(m => @Model.TaxRate)</div>
            </td>
            <td>
                <div id="updateText">
                    @{
                        if (@Model.UID != Guid.Empty && @Model.AccountList != null)
                        {
                            Html.RenderPartial("EditorTemplates/AccountList", @Model.AccountList);
                        }
                    }
                </div>
                @* <div id="detailed">
                    @{
                        if (@Model.UID != Guid.Empty && @Model.CurrencyDetail != null)
                        {
                            Html.RenderPartial("EditorTemplates/CurrencyDetailDTO", @Model.CurrencyDetail);
                        }
                    }
                </div>*@
                <div class="display-label">@Html.LabelFor(m => @Model.SelectedCfo)</div>
                @{ Html.RenderAction<CfoController>(x => x.RenderCfo(@Model.SelectedCfo)); }
                <div class="display-label">@Html.LabelFor(m => @Model.PaymentPurpose) @Html.ValidationMessageFor(x => x.PaymentPurpose)</div>
                <div class="editor-field">@Html.EditorFor(m => @Model.PaymentPurpose)</div>
                <div class="display-label">@Html.LabelFor(m => @Model.Description)</div>
                <div class="editor-field">@Html.EditorFor(m => @Model.Description)</div>
            </td>
        </tr>
    </table>
    <div class="display-label">@Html.ValidationMessageFor(x => x.SelectedPayee)</div>
    <div class="display-label">@Html.ValidationMessageFor(x => x.SelectedAccount)</div>
    <div class="display-label">@Html.ValidationMessageFor(x => x.SelectedCfo)</div>
    <div class="display-label">@Html.ValidationMessageFor(x => x.SelectedPaymentType)</div>
    <div class="display-label">@Html.ValidationMessageFor(x => x.SelectedBudgetItem)</div>
    <div class="display-label">@Html.ValidationMessageFor(x => x.SelectedPayer)</div>
    <div class="display-label">@Html.ValidationSummary(true)</div>
</fieldset>
<script type="text/javascript">
    function loadAccountDetailDTOPartialView(e) {
        $('#SelectedPayee').val(e.value);
        $('#updateText').empty();
        var url = '@Url.Action("GetAccountSelectedList", "Account", new { id = "value" })';
        $('#updateText').load(url.replace('value', e.value));
    }
    function loadCurrencyDetailDTOPartialView(e) {
        $('#SelectedAccount').val(e.value);
        $('#detailed').empty();
        var url = '@Url.Action("GetAccountDetails", "Account", new { id = "value" })';
        $('#detailed').load(url.replace('value', e.value));
    }
    function loadPayerListPartialView(e) {
        $('#updatePayer').empty();
        var url = '@Url.Action("RenderPayerByPaymentType", "Corporation", new { id = "value" })';
        $('#updatePayer').load(url.replace('value', e.value));
    }
</script>
